package edu.zhku.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MyMap {

	public static void main(String[]args)
	{
		Map<Integer, String> map = new HashMap<Integer, String>();
		
		//增加数据
		map.put(1001, "小红");
		map.put(1002, "小张");
		map.put(1003, "小明");
		map.put(1004, "小波");
		
		//删除数据
		map.remove(1004);
		
		//修改
		map.put(1002,"小涛");
		
		//插入数据
		map.put(1005,"小圳");
		
		//遍历集合  Entry对象 记录键和值
		System.out.println("遍历集合：");
		
		Set<Map.Entry<Integer, String>>alls = map.entrySet();
		for(Map.Entry<Integer, String> all: alls)
		{
			System.out.println(all);
		}

		//遍历值
		System.out.println("遍历值：");
		
		for(String v : map.values())
		{
			System.out.println(v);
		}
		
		//判断集合中是否有键值
		System.out.println("判断集合中是否有键值：");
		
		System.out.println(map.containsKey(1002));
		System.out.println(map.containsKey(1007));
		
		//根据键获取值
		System.out.println("根据键获取值：");
		
		Object value = map.get(1002);
		System.out.println(value);
		System.out.println(map.get(1007));
		
		//返回集合Map有多长
		System.out.println("Map长度:" + map.size());
		
		//输出map集合
		System.out.println(map);
		
		
	}
}
